package com.tanhua.dubbo.server.service;


import com.tanhua.dubbo.server.enums.IdType;
import org.omg.CORBA.IDLType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

//生成自增长的id，原理：使用redis的自增长值
@Service
public class IdService {
//    注入redis模板对象
    @Autowired
    private RedisTemplate redisTemplate;

    public Long created(IdType idType){
        String idKey="TANHUA_ID_"+idType.toString();
//        redis的自动增长策略
        return this.redisTemplate.opsForValue().increment(idKey);
    }
}
